//
//  HerosNextFatherViewController.m
//  LOLBOX
//
//  Created by lanou3g on 15/12/17.
//  Copyright © 2015年 张明. All rights reserved.
//

#import "HerosNextFatherViewController.h"
#import "HerosNextJiqiaoTableViewController.h"
#import "HerosNextChuzhuangTableViewController.h"
#import "HerosNextStoryTableViewController.h"
@interface HerosNextFatherViewController ()
@property(nonatomic,strong)UISegmentedControl *segment;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)NSMutableArray *allImageArray;
@property(nonatomic,strong)HerosNextJiqiaoTableViewController *hnjqVc;
@property(nonatomic,strong)HerosNextChuzhuangTableViewController *hnczVc;
@property(nonatomic,strong)HerosNextStoryTableViewController *hnstVc;
@end

@implementation HerosNextFatherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.allImageArray = [NSMutableArray array];
    self.view.backgroundColor = [UIColor orangeColor];
    [self createSegment];
//     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStyleDone) target:self action:@selector(leftButtonAction:)];
//收藏方法
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"收藏" style:(UIBarButtonItemStyleDone) target:self action:@selector(rightButtonAction:)];
    self.hnjqVc = [[HerosNextJiqiaoTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    self.hnczVc = [[HerosNextChuzhuangTableViewController alloc] init];
    self.hnstVc = [[HerosNextStoryTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    [self addChildViewController:self.hnjqVc];
    [self addChildViewController:self.hnczVc];
    [self addChildViewController:self.hnstVc];
    
    UISwipeGestureRecognizer * leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeAction:)];
    leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:leftSwipe];
    UISwipeGestureRecognizer * rightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipeAction:)];
    rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:rightSwipe];
    self.hnjqVc.aString = self.name;
    self.hnjqVc.price = self.price;
    self.hnczVc.aString = self.name;
    [self.view addSubview:self.hnjqVc.view];
  [self.segment addTarget:self action:@selector(segmentAction:) forControlEvents:(UIControlEventValueChanged)];
}
//返回上页面
//-(void)leftButtonAction:(UIBarButtonItem *)sender {
//[self.navigationController popToRootViewControllerAnimated:YES];
//}
#pragma mark - - -↔滑动

- (void)leftSwipeAction:(UISwipeGestureRecognizer *)sender {
    if (self.segment.selectedSegmentIndex < 2) {
        self.segment.selectedSegmentIndex += 1;
        [self segmentAction:self.segment];
    }
}
- (void)rightSwipeAction:(UISwipeGestureRecognizer *)sender {
    if (self.segment.selectedSegmentIndex > 0) {
        self.segment.selectedSegmentIndex -= 1;
        [self segmentAction:self.segment];
    }
}
#pragma  mark - 视图初始化
-(void)createSegment{
    NSArray *array = @[@"技巧",@"出装",@"故事"];
    self.segment = [[UISegmentedControl alloc] initWithItems:array];
    self.segment.frame = CGRectMake(0, 0, self.view.frame.size.width, 40);
    self.segment.tintColor = [UIColor blackColor];
    [self.view addSubview:self.segment];
}
-(void)segmentAction:(UISegmentedControl *)sender{
    switch (sender.selectedSegmentIndex) {
        case 0:
            [self p_transformController:self.hnczVc andToController:self.hnjqVc];
            [self p_transformController:self.hnstVc andToController:self.hnjqVc];
            break;
        case 1:
            [self p_transformController:self.hnjqVc andToController:self.hnczVc];
            [self p_transformController:self.hnstVc andToController:self.hnczVc];
            break;
        case 2:
            [self p_transformController:self.hnczVc andToController:self.hnstVc];
            [self p_transformController:self.hnjqVc andToController:self.hnstVc];
            break;
        default:
            break;
    }
}
- (void)p_transformController:(UIViewController *)fromController andToController:(UIViewController *)toController{
    [self transitionFromViewController:fromController toViewController:toController duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        
    } completion:^(BOOL finished) {
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
